Skip to content

Add MSG91 metadata tracking#135

Merged
ChiragAgg5k merged 6 commits into
mainfrom
feat/msg91-metadata
Jun 23, 2026
Merged

Add MSG91 metadata tracking#135
ChiragAgg5k merged 6 commits into
mainfrom
feat/msg91-metadata

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Jun 23, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Adds support for MSG91 request tracking metadata on SMS messages.

This introduces a provider-specific MetadataParameter enum for MSG91-supported metadata keys, stores optional metadata on SMS messages, and attaches supported metadata fields to MSG91 flow requests. CRQID and UUID are validated against MSG91 documented constraints before sending and are kept as request-level MSG91 fields.

GEOSMS now preserves SMS metadata when routing messages to a single downstream send. When GEOSMS fans out one message into multiple adapter sends, it derives unique request-level CRQID and UUID values per child request to avoid duplicated provider tracking identifiers while preserving correlation.

Test Plan

  • ./vendor/bin/phpunit tests/Messaging/Adapter/SMS/Msg91Test.php tests/Messaging/Adapter/SMS/GEOSMSTest.php
  • ./vendor/bin/pint --preset psr12 --test src/Utopia/Messaging/Adapter/SMS/Msg91.php src/Utopia/Messaging/Adapter/SMS/GEOSMS.php src/Utopia/Messaging/Adapter/SMS/Msg91/MetadataParameter.php src/Utopia/Messaging/Messages/SMS.php tests/Messaging/Adapter/SMS/Msg91Test.php tests/Messaging/Adapter/SMS/GEOSMSTest.php
  • ./vendor/bin/phpstan analyse --memory-limit=2G --level=6 src/Utopia/Messaging/Messages/SMS.php src/Utopia/Messaging/Adapter/SMS/Msg91.php src/Utopia/Messaging/Adapter/SMS/GEOSMS.php src/Utopia/Messaging/Adapter/SMS/Msg91/MetadataParameter.php tests/Messaging/Adapter/SMS/Msg91Test.php tests/Messaging/Adapter/SMS/GEOSMSTest.php

Related PRs and Issues

#XXXX

Have you read the Contributing Guidelines on issues?

Yes.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown

Greptile Summary

  • Adds optional metadata storage and accessors to SMS messages.
  • Introduces MSG91 metadata keys for supported tracking fields.
  • Adds MSG91 request-body filtering and validation for tracking metadata.
  • Updates GEOSMS to preserve metadata and derive per-child tracking IDs for split sends.
  • Extends MSG91 and GEOSMS tests for metadata handling.

Confidence Score: 3/5

The change needs attention before merge because generic GEOSMS routing can now apply provider-specific metadata validation before delegating to child adapters.

The touched area is small and covered by focused tests, but the split-send metadata path introduces cross-provider behavior that can reject otherwise valid sends.

src/Utopia/Messaging/Adapter/SMS/GEOSMS.php

T-Rex T-Rex Logs

What T-Rex did

  • Created a focused GEOSMS repro harness configured for two non-MSG91 adapters and an invalid MSG91 CRQID to exercise MSG91 validation.
  • Attempted to run the repro script, but the environment lacked a PHP executable, so runtime reproduction could not be performed.
  • Collected environment blocker evidence showing composer not found, php not found, and apt-get install blocked by permission denial.
  • Ran two geosms-metadata-routing attempts; both failed due to missing PHP, so no contract-mismatch finding was reported.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (5): Last reviewed commit: "Validate GEOSMS tracking metadata before..." | Re-trigger Greptile

Comment thread src/Utopia/Messaging/Adapter/SMS/Msg91.php
Comment thread src/Utopia/Messaging/Adapter/SMS/Msg91.php

@lohanidamodar lohanidamodar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tests failing make sure not related.

Comment thread src/Utopia/Messaging/Adapter/SMS/GEOSMS.php Outdated
Comment thread src/Utopia/Messaging/Adapter/SMS/Msg91.php Outdated
Comment thread src/Utopia/Messaging/Adapter/SMS/GEOSMS.php
@ChiragAgg5k ChiragAgg5k merged commit 3419ffb into main Jun 23, 2026
3 of 4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat/msg91-metadata branch June 23, 2026 04:24
Comment on lines +101 to +114
if (\count($batches) > 1 && $metadata !== null) {
foreach ([MetadataParameter::CRQID, MetadataParameter::UUID] as $parameter) {
$key = $parameter->value;

if (!\array_key_exists($key, $metadata)) {
continue;
}

if (!\is_string($metadata[$key])) {
throw new \InvalidArgumentException("Msg91 {$key} metadata must be a string.");
}

if (\strlen($metadata[$key]) > 80 || !\preg_match('/^[A-Za-z0-9_.-]+$/', $metadata[$key])) {
throw new \InvalidArgumentException("Msg91 {$key} metadata must be 80 characters or less and contain only alphanumeric characters, underscores, dots, or hyphens.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Scope MSG91 validation

GEOSMS is a generic router, but this branch applies MSG91-only CRQID and UUID rules whenever a send is split into multiple batches. A GEOSMS setup that routes only to non-MSG91 adapters can now reject metadata such as CRQID => "order 123" before any child adapter runs, even though those adapters would otherwise ignore or preserve the metadata. Because this runs before the per-adapter try block, the same invalid value also aborts the entire send() instead of being reported under the affected adapter while later batches continue. Please leave provider-specific validation to the MSG91 adapter, or only apply it inside the child-send path for batches that are actually sent through MSG91.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants